﻿#include "singup.h"
#include "ui_singup.h"
#include "mainwindow.h"
Singup::Singup(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Singup)
{
    ui->setupUi(this);
}

Singup::~Singup()
{
    delete ui;
}

void Singup::on_pushButton_2_clicked()
{
    MainWindow *w=new MainWindow;
    w->show();
    this->close();
}

void Singup::on_pushButton_clicked()
{
    sqlite_Init();
    QString username=ui->lineEdit_username->text();
    QString password=ui->lineEdit_password->text();
    QString suerpass=ui->lineEdit_surepassword->text();
    //判断密码是否一致
    if(password==suerpass)
    {
        QString sql=QString("insert into user(username,password) values('%1','%2');")
                .arg(username).arg(password);
        //创建执行语句
        QSqlQuery query;
        //判断执行结果
        if(!query.exec(sql))
        {
            qDebug()<<"insert into error";
            QMessageBox::information(this,"注册认证","插入失败");

        }else
        {
            qDebug()<<"insert into error";
            QMessageBox::information(this,"注册认证","插入成功");
            MainWindow *w=new MainWindow;
            w->show();
            this->close();
        }
    }else
    {
        QMessageBox::information(this,"注册认证","输入的两次密码不一致");
    }
}
